package com.sdhs.workflow.mapper;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sdhs.common.core.domain.entity.SysUser;
import com.sdhs.common.core.mapper.BaseMapperPlus;
import com.sdhs.workflow.domain.bo.TaskBo;
import com.sdhs.workflow.domain.vo.TaskVo;
import org.apache.ibatis.annotations.Param;
import org.flowable.engine.impl.persistence.entity.AttachmentEntity;

import java.util.List;


/**
 * 任务信息Mapper接口
 *
 * @author may
 * @date 2024-03-02
 */
@InterceptorIgnore(tenantLine = "true")
public interface ActTaskMapper extends BaseMapperPlus<TaskVo, TaskVo> {
    /**
     * 获取待办信息
     *
     * @param page         分页
     * @param taskBo 条件
     * @return 结果
     */
    Page<TaskVo> getTaskWaitByPage(@Param("page") Page<TaskVo> page, @Param("taskBo") TaskBo taskBo);

    List<TaskVo> getToDoByTaskWaitByBusinessKey(@Param("businessKey") String businessKey);

    /**
     * 获取 某流程 某个用户 的待办信息
     * @param taskBo 流程key
     * @return 结果
     */
    List<TaskVo> getToDoByTaskWaitByBusinessKeyAndUserId(@Param("taskBo") TaskBo taskBo);

    /**
     * 获取已办
     *
     * @param page         分页
     * @param taskBo 条件
     * @return 结果
     */
    Page<TaskVo> getTaskFinishByPage(@Param("page") Page<TaskVo> page, @Param("taskBo") TaskBo taskBo);

    /**
     * 查询当前用户的抄送
     *
     * @param page         分页
     * @param queryWrapper 条件
     * @return 结果
     */
    Page<TaskVo> getTaskCopyByPage(@Param("page") Page<TaskVo> page, @Param(Constants.WRAPPER) QueryWrapper<TaskVo> queryWrapper);

    /**
     * 更新业务数据状态
     * @param tableName: 业务数据表名
     * @param businessKey: 业务数据businessKey
     * @param approvalStatus: 业务数据状态
     * @return
     */
    int updateBusinessDataStatusByBusinessKey(@Param("tableName") String tableName, @Param("businessKey") String businessKey, @Param("approvalStatus") String approvalStatus );

    int updateMessageStatusByBusinessKeyAndReceiver(@Param("businessKey") Long businessKey, @Param("userName") String userName);

    /**
     * 更新业务数据状态
     * @param tableName: 业务数据表名
     * @param businessId: 业务数据id
     * @param businessKey: 业务数据businessKey
     * @param approvalStatus: 业务数据状态
     * @return
     */
    int updateBusinessDataStatusByBusinessId(
            @Param("tableName") String tableName,
            @Param("businessId") String businessId,
            @Param("businessKey") String businessKey,
            @Param("approvalStatus") String approvalStatus
    );

    /**
     * 根据流程实例id，查询流程实例发起人
     * @param procInstId 流程实例id
     * @return
     */
    TaskVo selectStartUserByProcInstId(@Param("procInstId") String procInstId);

    /**
     * 根据多个流程实例id，查询流程实例发起人
     * @param procInstIds 流程实例id
     * @return
     */
    List<TaskVo> selectStartUserByProcInstIds(@Param("procInstIds") List<String> procInstIds);

    /**
     * 根据多个流程实例id，查询流程任务发起人
     * @param procInstIds 流程实例id
     * @return
     */
    List<TaskVo> selectTaskAssigneeByProcInstIds(@Param("procInstIds") List<String> procInstIds);

    /**
     * 根据多个流程实例id，查询流程实例候选人
     * @param procInstIds 流程实例id
     * @return
     */
    List<TaskVo> selectTaskCandidateByProcInstIds(@Param("procInstIds") List<String> procInstIds);

    /**
     * 通过业务数据id，查询项目经理
     * @param tableName 业务数据表名
     * @param businessId 业务数据id
     * @return 结果
     */
    String getProjectManagerId(@Param("tableName") String tableName, @Param("businessId") String businessId);

    /**
     * 通过businessKey，查询业务数据
     * @param businessKey
     * @return
     */
    TaskVo selectBusinessInfoByBusinessKey(@Param("businessKey") String businessKey);

    boolean insertAttachmentEntity(AttachmentEntity attachmentEntity);
}
